@@ -27,7 +27,7 @@ public class MainActivity extends BaseActivity implements MainContract.View { |
||
27 | 27 |
|
28 | 28 |
@BindView(R.id.tv_box_status) TextView boxStatusTextView; |
29 | 29 |
@BindView(R.id.iv_box_status) ImageView boxStatusImageView; |
30 |
- @BindView(R.id.icon_no_data) android.view.View noDataLayout; |
|
30 |
+ @BindView(R.id.icon_no_data) View noDataLayout; |
|
31 | 31 |
@BindView(R.id.iv_add_session) ImageView addSessionBtn; |
32 | 32 |
@BindView(R.id.container_view) View containerView; |
33 | 33 |
@BindView(R.id.recycler_view_sessions) RecyclerView sessionsRecyclerView; |
@@ -70,13 +70,8 @@ public class MainActivity extends BaseActivity implements MainContract.View { |
||
70 | 70 |
jumpToSelectedSession( presenter.createNewSession()); |
71 | 71 |
} |
72 | 72 |
|
73 |
- @OnClick(R.id.iv_box_status) |
|
74 |
- void checkBoxStatus(){ |
|
75 |
- |
|
76 |
- } |
|
77 |
- |
|
78 | 73 |
@Override |
79 |
- public void showOrderSnackBar() { |
|
74 |
+ public void showSnackBar(String msg) { |
|
80 | 75 |
|
81 | 76 |
} |
82 | 77 |
|
@@ -10,7 +10,7 @@ public class MainContract { |
||
10 | 10 |
|
11 | 11 |
interface View extends BaseView { |
12 | 12 |
|
13 |
- void showOrderSnackBar(); |
|
13 |
+ void showSnackBar(String msg); |
|
14 | 14 |
void showBoxDisconnectedView(); |
15 | 15 |
void showBoxConnectedView(); |
16 | 16 |
void showEmptyView(); |
@@ -25,14 +25,19 @@ import ai.pai.lensman.db.Preferences; |
||
25 | 25 |
import ai.pai.lensman.service.OrderDealService; |
26 | 26 |
import ai.pai.lensman.service.UploadService; |
27 | 27 |
|
28 |
-public class MainPresenter implements MainContract.Presenter,BaseInteractor.InteractorListener<ArrayList<String>>,UploadService.PhotoUploadListener { |
|
28 |
+class MainPresenter implements MainContract.Presenter,BaseInteractor.InteractorListener<ArrayList<String>>, |
|
29 |
+ UploadService.PhotoUploadListener, QueryBoxStatusInteractor.BoxStatusListener { |
|
29 | 30 |
|
30 |
- private MainContract.View uploadView; |
|
31 |
- private ArrayList<SessionBean> sessionList; |
|
32 |
- private String lensmanId; |
|
33 | 31 |
private int sessionSeq; |
32 |
+ private String lensmanId; |
|
34 | 33 |
private ArrayList<String> sessionIds; |
34 |
+ |
|
35 |
+ private ArrayList<SessionBean> sessionList; |
|
36 |
+ |
|
37 |
+ private MainContract.View view; |
|
35 | 38 |
private FetchSessionIdsInteractor interactor; |
39 |
+ private QueryBoxStatusInteractor boxStatusInteractor; |
|
40 |
+ |
|
36 | 41 |
private ServiceConnection serviceConnection; |
37 | 42 |
|
38 | 43 |
private BroadcastReceiver wifiReceiver = new BroadcastReceiver() { |
@@ -40,19 +45,20 @@ public class MainPresenter implements MainContract.Presenter,BaseInteractor.Inte |
||
40 | 45 |
public void onReceive(Context context, Intent intent) { |
41 | 46 |
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) { |
42 | 47 |
if(NetworkUtil.isWifiConnected(context)){ |
43 |
- uploadView.showBoxConnectedView(); |
|
48 |
+ view.showBoxConnectedView(); |
|
44 | 49 |
}else{ |
45 |
- uploadView.showBoxDisconnectedView(); |
|
50 |
+ view.showBoxDisconnectedView(); |
|
46 | 51 |
} |
47 | 52 |
} |
48 | 53 |
} |
49 | 54 |
}; |
50 | 55 |
|
51 |
- public MainPresenter(MainContract.View view){ |
|
52 |
- this.uploadView = view; |
|
56 |
+ MainPresenter(MainContract.View view){ |
|
57 |
+ this.view = view; |
|
53 | 58 |
this.lensmanId = Preferences.getInstance().getLensManId(); |
54 | 59 |
sessionIds = new ArrayList<>(); |
55 | 60 |
interactor = new FetchSessionIdsInteractor(lensmanId,100,this); |
61 |
+ boxStatusInteractor = new QueryBoxStatusInteractor(this); |
|
56 | 62 |
serviceConnection = new ServiceConnection() { |
57 | 63 |
@Override |
58 | 64 |
public void onServiceConnected(ComponentName componentName, IBinder iBinder) { |
@@ -70,28 +76,29 @@ public class MainPresenter implements MainContract.Presenter,BaseInteractor.Inte |
||
70 | 76 |
@Override |
71 | 77 |
public void start() { |
72 | 78 |
if(NetworkUtil.isWifiConnected(App.getAppContext())){ |
73 |
- uploadView.showBoxConnectedView(); |
|
79 |
+ view.showBoxConnectedView(); |
|
74 | 80 |
}else{ |
75 |
- uploadView.showBoxDisconnectedView(); |
|
81 |
+ view.showBoxDisconnectedView(); |
|
76 | 82 |
} |
77 | 83 |
|
78 | 84 |
if(sessionIds==null|| sessionIds.size()<20){ |
79 | 85 |
interactor.startJob(); |
80 | 86 |
} |
81 | 87 |
if(sessionIds==null || sessionIds.size()<1){ |
82 |
- uploadView.setNewSessionBtnEnabled(false); |
|
88 |
+ view.setNewSessionBtnEnabled(false); |
|
83 | 89 |
}else{ |
84 |
- uploadView.setNewSessionBtnEnabled(true); |
|
90 |
+ view.setNewSessionBtnEnabled(true); |
|
85 | 91 |
} |
86 | 92 |
sessionList = DBService.getInstance().getSessionBeanListByDay(getSessionDateInLongFormat()); |
87 | 93 |
if(sessionList.size()==0){ |
88 |
- uploadView.showEmptyView(); |
|
94 |
+ view.showEmptyView(); |
|
89 | 95 |
}else{ |
90 |
- uploadView.showSessionViews(); |
|
91 |
- uploadView.refreshSessionViews(sessionList); |
|
96 |
+ view.showSessionViews(); |
|
97 |
+ view.refreshSessionViews(sessionList); |
|
92 | 98 |
} |
93 | 99 |
sessionSeq = sessionList.size(); |
94 | 100 |
registerWifiChangeReceiver(); |
101 |
+ boxStatusInteractor.startJob(); |
|
95 | 102 |
App.getAppContext().startService(new Intent(App.getAppContext(), OrderDealService.class)); |
96 | 103 |
App.getAppContext().startService(new Intent(App.getAppContext(), UploadService.class)); |
97 | 104 |
App.getAppContext().bindService(new Intent(App.getAppContext(),UploadService.class),serviceConnection, Context.BIND_AUTO_CREATE); |
@@ -99,6 +106,7 @@ public class MainPresenter implements MainContract.Presenter,BaseInteractor.Inte |
||
99 | 106 |
|
100 | 107 |
@Override |
101 | 108 |
public void stop() { |
109 |
+ boxStatusInteractor.cancelJob(); |
|
102 | 110 |
App.getAppContext().unbindService(serviceConnection); |
103 | 111 |
App.getAppContext().unregisterReceiver(wifiReceiver); |
104 | 112 |
} |
@@ -125,8 +133,8 @@ public class MainPresenter implements MainContract.Presenter,BaseInteractor.Inte |
||
125 | 133 |
@Override |
126 | 134 |
public void onInteractSuccess(ArrayList<String> sessionIds) { |
127 | 135 |
this.sessionIds.addAll(sessionIds); |
128 |
- uploadView.setNewSessionBtnEnabled(true); |
|
129 |
- uploadView.showBoxConnectedView(); |
|
136 |
+ view.setNewSessionBtnEnabled(true); |
|
137 |
+ view.showBoxConnectedView(); |
|
130 | 138 |
} |
131 | 139 |
|
132 | 140 |
@Override |
@@ -134,7 +142,7 @@ public class MainPresenter implements MainContract.Presenter,BaseInteractor.Inte |
||
134 | 142 |
if(NetworkUtil.isWifiConnected(App.getAppContext())){ |
135 | 143 |
interactor.startJob(); |
136 | 144 |
}else{ |
137 |
- uploadView.showBoxDisconnectedView(); |
|
145 |
+ view.showBoxDisconnectedView(); |
|
138 | 146 |
} |
139 | 147 |
|
140 | 148 |
} |
@@ -162,7 +170,7 @@ public class MainPresenter implements MainContract.Presenter,BaseInteractor.Inte |
||
162 | 170 |
} |
163 | 171 |
} |
164 | 172 |
sessionBean.sessionPhotos = photoList; |
165 |
- uploadView.updateSessionUploadViewAt(position); |
|
173 |
+ view.updateSessionUploadViewAt(position); |
|
166 | 174 |
} |
167 | 175 |
|
168 | 176 |
@Override |
@@ -187,7 +195,7 @@ public class MainPresenter implements MainContract.Presenter,BaseInteractor.Inte |
||
187 | 195 |
} |
188 | 196 |
} |
189 | 197 |
sessionBean.sessionPhotos = photoList; |
190 |
- uploadView.updateSessionUploadViewAt(position); |
|
198 |
+ view.updateSessionUploadViewAt(position); |
|
191 | 199 |
} |
192 | 200 |
|
193 | 201 |
private void registerWifiChangeReceiver() { |
@@ -196,4 +204,12 @@ public class MainPresenter implements MainContract.Presenter,BaseInteractor.Inte |
||
196 | 204 |
} |
197 | 205 |
|
198 | 206 |
|
207 |
+ @Override |
|
208 |
+ public void onBoxStatusFetched(String boxNo, String boxStatus, String boxStatusCode) { |
|
209 |
+ if("0".equals(boxStatusCode)){ |
|
210 |
+ view.showBoxConnectedView(); |
|
211 |
+ }else{ |
|
212 |
+ view.showBoxDisconnectedView(); |
|
213 |
+ } |
|
214 |
+ } |
|
199 | 215 |
} |